Ext.define( 'js.ranInsOfProQui.RandomInspectionOfProjectQualityBg', {
    extend: 'Ext.panel.Panel',
    id: 'RandomInspectionOfProjectQualityBg',
    requires: ['js.Util', 'js.ctrl.Common',],
    controller: 'Common',
    autoScroll : true,
    margin:'0 0 30 0',
    config: {
        layout: {
            type: 'vbox',
            align: 'stretch'
        },
    },
    bodyStyle:{
        background:'#fff'
    },
    initComponent: function () {
        let titleA  = {
            xtype: 'panel',
            html:'<img src="../../img/flagA.png" style="width:22px;height:22px;"><span style="margin-left: 10px;position: relative;top: 5px;color:#000;font-size:20px;">质保体系抽查</span>'
        };
        let  titletB = {
            xtype: 'panel',
            html:'<img src="../../img/flagA.png" style="width:22px;height:22px;"><span style="margin-left: 10px;position: relative;top: 5px;color:#000;font-size:20px;">质量行为抽查</span>'
        };
        let titleone={
            xtype: 'panel',
            margin: '30 30 10 30',
            bodyStyle: "background-color:#FFF;",
            items:[titleA,{
                xtype : "button",
                height:'40',
                cls:'buttonAAA',
                action_type: 'projectMergerAdd',
                check_type:'1',
                engineering_id:this.engineering_id,
                handler: this.RanCheckOfQuaLehaviorAdd,
                width: '100',
                text:'添加'
            }]
        }

        let listone = Ext.create('js.ranInsOfProQui.RandomInspectionOfQualityAssuranceSystemPage',{
            engineering_id: this.engineering_id,
        });

        let titletwo={
            xtype: 'panel',
            margin: '50 30 30 30',
            bodyStyle: "background-color:#FFF;",
            items:[titletB,{
                xtype : "button",
                height:'40',
                cls:'buttonAAA',
                width: '100',
                check_type:'2',
                engineering_id:this.engineering_id,
                handler: this.RanCheckOfQuaLehaviorAAdd,
                text:'添加'
            }]
        }
        let listtwo = Ext.create('js.ranInsOfProQui.RandomInspectionOfQualityBehaviorPage',{
            engineering_id: this.engineering_id,
        });

        this.items = [
            titleone,
            listone,
            titletwo,
            listtwo
        ];
        this.callParent(arguments);
    },
    RanCheckOfQuaLehaviorAdd: function (btn) {
        let params = {
            engineering_id:btn.engineering_id,
            check_type:btn.check_type,
        };
        let btnCancel = Ext.create('Ext.button.Button', {
            cls: 'btnCancel',
            text: `取消`,
            scale: 'medium',
            width:140,
            height:40,
            margin:'0 0 20 200',
            handler: function (btn) {
                btn.up('window').close();
            },
            scope: this

        });
        let btnSubmit = Ext.create('Ext.button.Button', {
            cls:'btnSubmit',
            border:false,
            text: `保存`,
            margin: '0 0 20 30',
            width:140,
            height:40,
            scale: 'medium',
            handler: function (btn) {
                   let rectification_date=Ext.getCmp('rectification_date').getValue();
                   let unit_type=Ext.getCmp('unit_type').getValue();
                   let check_result=Ext.getCmp('check_result').getValue().check_result?Ext.getCmp('check_result').getValue():Ext.getCmp('check_result').value;
                   let userIds=Ext.getCmp('userIdsObject_person').getValue();
                   let check_details=Ext.getCmp('check_details').getValue();
                   let check_date=Ext.getCmp('check_date').getValue();
                   let rectification_notice=Ext.getCmp('rectification_notice').getValue();
                   let rectification_reply=Ext.getCmp('rectification_reply').getValue();
                   let remarks=Ext.getCmp('remarks').getValue();
                if(check_date===''||unit_type===null||userIds===''||check_details===''){
                    Ext.toast('请将信息填写完整');
                }else {
                    let panel =Ext.getCmp('RandomInspectionOfProjectQualityBg')
                    panel.mask('正在加载数据请稍后');
                    util.post('/qualityCheckRoutes', {
                        action_type: 'qualityCheckAdd',
                        check_type: params.check_type,
                        engineering_id: params.engineering_id,
                        unit_type: unit_type,
                        rectification_date:rectification_date,
                        check_result: check_result,
                        userIds: userIds,
                        check_details: check_details,
                        check_date: check_date,
                        rectification_notice: rectification_notice,
                        rectification_reply: rectification_reply,
                        remarks: remarks,
                    }).then(function (response) {
                        panel.unmask();
                        let obj = Ext.decode(response.responseText);
                        if (obj.success) {
                            Ext.toast('保存成功');
                            let me = Ext.getCmp('RandomInspectionOfQualityAssuranceSystemPage');
                            me.store.reload();
                            let meA = Ext.getCmp('RandomInspectionOfQualityBehaviorPage');
                            meA.store.reload();
                            btn.up('window').close();
                        } else {
                            Ext.toast(`保存失败,${obj.message}`);
                        }
                    });
                }
            },
            scope: this
        });
        let formPanel = Ext.create('js.ranInsOfProQui.ranInsOfProQuiAddPage', {
            hidenField: params,
            id: 'ranInsOfProQuiAddPage'
        });
        let win = util.window(formPanel, {title:'新增质保体系抽查' ,width:'58%',height:'90%', buttons: ['->', btnCancel, btnSubmit, '->']});
        win.show();
        formPanel.on('actioncomplete', () => {
            this.getStore().reload();
            win.close();
        });
    },
    RanCheckOfQuaLehaviorAAdd: function (btn) {
        let params = {
            engineering_id:btn.engineering_id,
            check_type:btn.check_type,
        };
        let btnCancel = Ext.create('Ext.button.Button', {
            cls: 'btnCancel',
            text: `取消`,
            scale: 'medium',
            width:140,
            height:40,
            margin:'0 0 20 200',
            handler: function (btn) {
                btn.up('window').close();
            },
            scope: this

        });
        let btnSubmit = Ext.create('Ext.button.Button', {
            cls:'btnSubmit',
            border:false,
            text: `保存`,
            margin: '0 0 20 30',
            width:140,
            height:40,
            scale: 'medium',
            handler: function (btn) {
                let rectification_date=Ext.getCmp('rectification_date').getValue();
                let check_result=Ext.getCmp('check_result').getValue().check_result?Ext.getCmp('check_result').getValue():Ext.getCmp('check_result').value;
                let userIds=Ext.getCmp('userIdsObject_person').getValue();
                let check_details=Ext.getCmp('check_details').getValue();
                let check_date=Ext.getCmp('check_date').getValue();
                let rectification_notice=Ext.getCmp('rectification_notice').getValue();
                let rectification_reply=Ext.getCmp('rectification_reply').getValue();
                let remarks = Ext.getCmp('remarks').getValue();
                if(check_date===''||userIds===''||check_details===''){
                    Ext.toast('请将信息填写完整');
                }else {
                    let panel =Ext.getCmp('RandomInspectionOfProjectQualityBg')
                    panel.mask('正在加载数据请稍后');
                    util.post('/qualityCheckRoutes', {
                        action_type: 'qualityCheckAdd',
                        rectification_date:rectification_date,
                        engineering_id: params.engineering_id,
                        check_type: params.check_type,
                        check_result: check_result,
                        userIds: userIds,
                        check_details: check_details,
                        check_date: check_date,
                        rectification_notice: rectification_notice,
                        rectification_reply: rectification_reply,
                        remarks: remarks,
                    }).then(function (response) {
                        panel.unmask();
                        let obj = Ext.decode(response.responseText);
                        if (obj.success) {
                            Ext.toast('保存成功');
                            let me = Ext.getCmp('RandomInspectionOfQualityAssuranceSystemPage');
                            me.store.reload();
                            let meA = Ext.getCmp('RandomInspectionOfQualityBehaviorPage');
                            meA.store.reload();
                            btn.up('window').close();
                        } else {
                            Ext.toast(`保存失败,${obj.message}`);
                        }
                    });
                }
            },
            scope: this
        });
        let formPanel = Ext.create('js.ranInsOfProQui.ranInsOfProQuiAAddPage', {
            hidenField: params,
            id: 'ranInsOfProQuiAddPage'
        });
        let win = util.window(formPanel, {title:'新增质量行为抽查' ,width:'58%',height:'83%', buttons: ['->', btnCancel, btnSubmit, '->']});
        win.show();
        formPanel.on('actioncomplete', () => {
            this.getStore().reload();
            win.close();
        });
    },
});